//
//  GWBadgeView.m
//  新浪微博
//
//  Created by qianfeng on 16/2/25.
//  Copyright (c) 2016年 高炜. All rights reserved.
//

#import "GWBadgeView.h"

@implementation GWBadgeView

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self =[super initWithFrame:frame]) {
        UIImage *image =[UIImage reSizeWithName:@"main_badge"];
        [self setBackgroundImage:image forState:UIControlStateNormal];
        self.titleLabel.font =[UIFont systemFontOfSize:11];
        self.height =image.size.height;
    }
    return self;
}
-(void)setBadgeValue:(NSString *)badgeValue
{
    _badgeValue =badgeValue;
    [self setTitle:badgeValue forState:UIControlStateNormal];
    UIImage *image =[UIImage imageNamed:@"main_badge"];
    CGSize size =[badgeValue boundingRectWithSize:CGSizeMake(200, 20) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.titleLabel.font} context:0].size;
    if (size.width<image.size.width) {
        self.width =image.size.width;
    }
    else
    {
        self.width =size.width+10;
    }
}
@end
